//
//  OrdersTableViewController.m
//  AppointmentForCar
//
//  Created by Herron on 16/10/3.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "OrdersTableViewController.h"
#import "OrderCell.h"
#import "OrderModel.h"

@interface OrdersTableViewController ()

@property (nonatomic, strong) NSMutableArray *tableArray;

@end

@implementation OrdersTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"历史行程";
    [self.tableView registerNib:[UINib nibWithNibName:@"OrderCell" bundle:nil] forCellReuseIdentifier:@"OrderCellID"];
    [self.tableView setRowHeight:140];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableArray = @[].mutableCopy;
    [HUDManager showLoadingHUDViewWithText:@"正在加载"];
    [NetWork postNetWorkWithUrl:kURLUserHistoryJourney parame:@{@"id":[UserAccountManager shareUserManager].user.userId} successBlock:^(NSDictionary *dic) {
        NSLog(@"dic = %@", dic);
        NSArray *dataArray = dic[@"data"][@"journeys"];
        if (dataArray.count) {
            [HUDManager hideHUDView];
            self.tableArray = [OrderModel arrayOfModelsFromDictionaries:dataArray error:nil];
            [self.tableView reloadData];
        } else {
            [HUDManager showWarningWithText:dic[@"message"]];
        }
    } errorBlock:^(id error) {
        [HUDManager showWarningWithText:@"网络异常"];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderModel *order = self.tableArray[indexPath.row];
    OrderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderCellID" forIndexPath:indexPath];
    [cell setupCell:order];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}


@end
